<?php
use app\common\model\User;
use app\common\model\Shop;
use app\common\model\Msg as MsgModel;
use think\facade\Log;

/**
 * 订单事件
 * Class OrderSubscribe
 * @package crmeb\subscribes
 */
class OrderSubscribe
{
		
	/**
    * 订单创建
    * @param array $event
     */
    public function onOrderCreated($order)
    {
		return true;
    }
	
    /**
    * 订单支付成功
    * @param array $event
     */
    public function onOrderPaySuccess($order)
    {
        //更新用户支付订单数量
        User::where('id',$order['uid'])->setInc('pay_count',1);
		//发送消息给商家
		$reciveId = Shop::where('id',$order['shop_id'])->value('uid');
		$content = "您有一笔新的订单，赶快去处理吧！";
	   	(new MsgModel)->send(0,$reciveId,$content,2,$order['order_no']);
		//返回
		return true;
    }
	
	
	
	/**
    * 用户确认收货
    * @param array $event
     */
    public function onUserOrderTake($order)
    {
		//发送消息给商家
		$reciveId = Shop::where('id',$order['shop_id'])->value('uid');
		$content = "您有一笔新的待发货订单，赶快去发货吧！";
	   	(new MsgModel)->send(0,$reciveId,$content,2,$order['order_no']);
		//返回
		return true;
    }
	
	
	/**
    * 用户申请退款
    * @param array $event
     */
    public function onUserOrderApplyRefund($order)
    {
		//发送消息给商家
		$reciveId = Shop::where('id',$order['shop_id'])->value('uid');
	   	(new MsgModel)->send(0,$reciveId,"您有一笔退款申请，赶快去查看吧！",1,$order['order_no'],2);
		//返回
		return true;
    }
	
	
	/**
    * 发货
    * @param array $event
     */
    public function onUserOrderSeed($order)
    {
		//发送消息给用户
	   	(new MsgModel)->send(0,$order['uid'],"您有一笔订单已发货，请注意查收！",2,$order['order_no']);
		//返回
		return true;
    }
	
	
	/**
    * 用户删除订单
    * @param array $event
     */
    public function onUserOrderRemoved($order)
    {
		
		return true;
    }
}